package xconsole

import (
	"flag"
	"fmt"

	"gitee.com/xiaoyutab/xgotool/xnum"
	"gitee.com/xiaoyutab/xgotool/xstring"
)

// 根据传入的参数和类型生成结构体中的某一行
func kstruct(help bool) string {
	if help {
		return "根据传入的参数和类型生成结构体中的某一行"
	}
	field := ""
	has_gorm := false
	has_jn := false
	types := ""
	flag.StringVar(&field, "f", "demo", "格式化的字段描述")
	flag.BoolVar(&has_gorm, "g", false, "是否输出gorm结构类型定义")
	flag.StringVar(&types, "t", "string", "变量类型")
	flag.BoolVar(&has_jn, "j", false, "是否忽略json兼容，若传入此值的话将会直接使用type类型，而不再转为json.Number进行兼容")
	flag.Parse()
	jianrong_type := []string{"int8", "uint8", "int16", "uint16", "int", "uint", "int32", "uint32", "int64", "uint64", "float32", "float64"}
	if !has_jn && xnum.InArray(types, jianrong_type) {
		types = "json.Number"
	}
	fmt.Println()
	gfield := fmt.Sprintf("`json:\"%s\" form:\"%s\"", field, field)
	if has_gorm {
		gfield += fmt.Sprint(" gorm:\"field:%s\"", field)
	}
	gfield += "`"
	fmt.Printf("\t%s\t%s\t%s\t// \n\n", xstring.CamelCase(field), types, gfield)
	return ""
}
